<template>
	<view class="new-users copy-data">
		<!-- 背景 -->
		<view class="bg"></view>
		<!-- 头部用户信息 -->
		<view class="user-card">
			<view class="user-info">
				<image class="avatar" :src='userInfo.avatar'></image>
				<view class="info">
					<view class="name">{{agentInformation.agentNickName}}</view>
					<view class="create-time" style="font-size: 24rpx;">
						开通时间:{{agentInformation.createTime}}
					</view>
				</view>
			</view>
		</view>
		<!-- 营业额信息 -->
		<view class="moneyBox">
			<view class="topMoney">
				<text style="text-align: left;">可开设商家数量：<text
						style="color:#2676DF">{{agentInformation.allowToOpen}}</text></text>
				<text style="text-align: right;">已开设商家数量：<text
						style="color:#2676DF">{{agentInformation.currentManagement}}</text></text>
			</view>
		</view>
		<view class="moneyBox">
			<view class="money-details">
				<p class="p1">{{turnover[0].name}}</p>
				<p class="p1">{{turnover[1].name}}</p>
				<p class="p1">{{turnover[2].name}}</p>
				<p class="p2">{{ turnover[0].value || 0 }}</p>
				<p class="p2">{{ turnover[1].value || 0 }}</p>
				<p class="p2">{{ turnover[2].value || 0 }}</p>
				<view class="divider"></view>
				<p class="p1">{{turnover[3].name}}</p>
				<p class="p1">{{turnover[4].name}}</p>
				<p class="p1">{{turnover[5].name}}</p>
				<p class="p2">{{ turnover[3].value || 0 }}</p>
				<p class="p2">{{ turnover[4].value || 0 }}</p>
				<p class="p2">{{ turnover[5].value || 0 }}</p>
			</view>
		</view>
		<!-- 店铺列表开始 -->
		<view class="store-list-container">
			<view class="store-item-wrapper" v-for="(store, index) in agentStoreList" :key="index">
				<view class="store-header">
					<view class="store-name-address">
						<p class="store-name">{{ store.storeName }}</p>
						<p class="store-address">{{ store.storeAddress }}</p>
					</view>
					<view class="store-today-income" style="color: #2676DF;">
						今日佣金: {{ store.todayIncome }}
					</view>
				</view>
				<view class="store-divider"></view>
				<view class="store-bottom-line">
					<view class="store-today-sales">
						今日营业额: {{ store.todaySales }}
					</view>
					<view class="store-today-order-count">
						今日订单数: {{ store.todayOrderCount }}
					</view>
				</view>
			</view>
		</view>
		<!-- 店铺列表结束 -->
	</view>
</template>

<script>
	import {
		getUserInfo
	} from '@/api/user.js';
	import {
		getAgentInformation,
		getTurnover,
		getAgentStoreList
	} from '@/api/business.js';

	export default {
		data() {
			return {
				userInfo: {},
				agentInformation: {},
				turnover: [],
				agentStoreList: []
			};
		},
		onLoad() {},
		onShow() {
			this.getUserDetail();
		},
		methods: {
			getUserDetail() {
				getUserInfo().then((res) => {
					this.userInfo = res.data;
					this.getStoreDetail(this.userInfo.uid);
				});
			},
			getStoreDetail(id) {
				getAgentInformation(id).then(res => {
					this.agentInformation = res.data;
				});
				getTurnover(id).then(res => {
					this.turnover = res.data;
				});
				getAgentStoreList(id).then(res => {
					this.agentStoreList = res.data;
				});
			},
		}
	};
</script>
<style lang="scss" scoped>
	page,
	body {
		height: 100%;
		background-color: #F9F9F9;
	}

	.bg {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 400rpx;
		background: linear-gradient(0deg, #F9F9F9, #E2F0FF, #C5EBFE);
		// background: url('http://store-profit-system.oss-cn-shanghai.aliyuncs.com/wisdomClubApp/businessBag.png');
		// background-repeat: no-repeat;
		// background-size: 100% 100%;
	}

	.new-users {
		display: flex;
		flex-direction: column;

		.user-card {
			position: relative;
			width: 100%;
			margin: 0 auto;
			padding: 30rpx;

			.user-info {
				display: flex;

				.avatar {
					width: 110rpx;
					height: 110rpx;
					border-radius: 50%;
					border: 2rpx solid #fff;
				}

				.info {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					margin-left: 20rpx;
					padding: 15rpx 0;

					.name {
						color: #333333;
						font-size: 31rpx;
					}

					.create-time {
						color: #666666;
						font-size: 24rpx;
					}
				}
			}
		}
	}

	.moneyBox {
		display: flex;
		flex-wrap: wrap;
		position: relative;
		border-radius: 30rpx;
		margin: 0rpx 30rpx;

		.topMoney {
			width: 100%;
			font-weight: 400;
			font-size: 28rpx;
			display: flex;
			justify-content: space-between;
		}

		.money-details {
			width: 100%;
			text-align: center;
			display: flex;
			flex-wrap: wrap;
			border-radius: 30rpx;
			background: linear-gradient(0deg, #E2F0FF, #F9F9F9);
			// box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
			padding: 30rpx 40rpx;
			border: 2rpx solid #fff;
			margin-top: 40rpx;

			.divider {
				width: 100%;
				height: 2rpx;
				background-color: #ccc;
				margin: 20rpx 0;
			}

			.p1 {
				width: 33%;
				font-weight: 400;
				font-size: 26rpx;
				color: #666666;
			}

			.p2 {
				width: 33%;
				font-weight: 800;
				font-size: 38rpx;
				color: #2676DF;
			}
		}
	}

	.store-list-container {
		display: flex;
		flex-direction: column;
		margin: 0 30rpx;

		.store-item-wrapper {
			width: 100%;
			border-radius: 30rpx;
			background: #fff;
			padding: 30rpx 40rpx;
			margin-top: 20rpx;

			.store-header,
			.store-bottom-line {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.store-header {
				margin-bottom: 20rpx;
			}

			.store-name-address {
				text-align: left;

				.store-name {
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;
					width: 400rpx;
					word-wrap: break-word; 
					overflow-wrap: break-word;
					white-space: normal; 
				}

				.store-address {
				    font-size: 26rpx;
				    color: #999999;
				    margin-top: 10rpx;
				    width: 400rpx; 
				    word-wrap: break-word; 
				    overflow-wrap: break-word;
				    white-space: normal; 
				}
			}

			.store-today-income,
			.store-today-sales,
			.store-today-order-count {
				font-size: 26rpx;
				color: #999999;
			}

			.store-divider {
				width: 100%;
				height: 2rpx;
				background-color: #ccc;
				margin: 20rpx 0;
			}
		}
	}
</style>